﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Bulid_List_Input.ascx.cs" Inherits="ZLDC.Estate.UserControl.Bulid_List_Input" %>
<!-- 根据楼盘，查询出下面的所有栋阁 -->
<link href="../js/jquery.autocomplete/jquery.autocomplete.css" rel="stylesheet" type="text/css" />
<script src="../js/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="../js/jquery.autocomplete/jquery.autocomplete.min.js" type="text/javascript"></script>
<script type="text/javascript">


//    $(function() {

//    $('#iBuildList').autocomplete("../Handler/HandlerIndex.ashx?act=buildlist_ByEname", {
//           
//            minChars: 1,
//            extraParams: { ename: function() { return $('#iEstateName').val(); } },
//            max: 100,
//            //列表里的条目数
//            width: 205,
//            scroll: true,
//            mustMatch: true,
//            matchContains: false,
//            //提示的宽度，溢出隐藏
//            scrollHeight: 300,
//            //提示的高度，溢出显示滚动条
//            parse: function(data) {
//                if (data == "" || data == undefined)
//                    return;

//                return $.map(eval(data), function(row) {
//                    return {
//                        data: row,
//                        value: row.id,
//                        result: row.name
//                    }
//                });
//            },
//            formatItem: function(item) {
//                return item.finalname;
//            }
//        });

//        $("#iBuildList").result(function(event, data, formatted) {
//            // 选中下拉中某行的事件
//            if (data == null) {
//                return;
//            }
//            var finalName = data.finalname.replace(data.ename, "");
//            $("#iBuildList").val(finalName);
//            $("#buildName1").val(data.id);
//            $("#level").val(data.level);

//        });
//    });
    function loadBuild() {
        var ename = $("#iEstateName").val();        // 楼盘名称
        var buildname = $("#iBuildList").val();

        if ((typeof (ename) == "undefined") || ($("#iEstateName").val() == ""))
            ename = "";
        
      
        $.ajax({
            type: 'POST',
            url: '../Handler/HandlerIndex.ashx',
            data: 'act=buildlist_ByEname&ename=' + escape(ename) + '&q=' + escape(buildname),
            timeout: '20000',
            error: function() {
               
            }, success: function(json) {
                if (json != "") {
                    loadBuildCallBack(json);
                }
            }
        });
    }

    // 栋阁回调
    function loadBuildCallBack(response) {
        var json = eval("(" + response + ")");
        var record = json.record;

        var strDiv = "";
        if (record == null || record.length == 0) {
            return;
        }

        // 显示下拉框
        document.getElementById("divBuildlist").style.display = "block";
        
        var recordLength = record.length;
        for (var i = 0; i < recordLength; i++) {
            var buildname = record[i].finalname.replace(record[i].ename, "");
            strDiv += "<input type='checkbox' style='cursor: pointer;' onclick=\"QuResult(this,'" + buildname + "','" + record[i].id + "'," + record[i].level + ")\"  id='divcheck'/>" + buildname + " " + record[i].othername + "";
            if(i<recordLength)
              strDiv+="</br>";

        }
        document.getElementById("divBuildlist").innerHTML = strDiv;
    }
    
    
    // 设置输入框默认值
    function setText() {
        if (document.getElementById("iEstateName").value == "") {
            $("#iBuildList").val("");
            $("#buildName1").val("");
            $("#level").val("");
            document.getElementById("floor").value = "";
            document.getElementById("roomNo").value = "";
            document.getElementById("roomid").value = "";
       }
    }
    // 清除输入框默认值
    function clearText() {
        
        $("#iBuildList").val("");
        $("#buildName1").val("");
        $("#level").val("");

        document.getElementById("floor").value = "";
        document.getElementById("roomNo").value = "";
        document.getElementById("roomid").value = "";
    }
    // 单选
    function QuResult(e,buildname, bid, level) {
        if (e.checked) {
            $("#iBuildList").val(buildname);
            $("#buildName1").val(bid);
            $("#level").val(level);
            
        } else {
            $("#iBuildList").val("");
            $("#buildName1").val("");
            $("#level").val("");

        }
        document.getElementById("divBuildlist").style.display = "none";

    }
    function ClearDiv() {
        document.getElementById("divBuildlist").style.display = "none";
    }
    

</script>
<div id="con">
    <input id="iBuildList" name="iBuildList" class="textstyle1"   style="width: 150px;" onclick="loadBuild();" onkeyup="loadBuild();ClearDiv();"  onblur="setText();"/>
    <input id="buildName1" name="buildName1"  type="hidden" />
    <input id="level" name="level"   type="hidden" />
</div>
<div id="divBuildlist"  style="overflow: auto; z-index: 2;   position: absolute; display: none;
    border: 1px; border-style: solid; background-color: #ffffff; height: 250px; width: 150px;
    text-align: left;">
</div>



